#include <iostream>
#include <any_element_within_range.h>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <list>
#include <boost/foreach.hpp>
#include <stlhelper.h>

unsigned RANGE = 1000;
unsigned COUNT = 10;

using namespace std;
using namespace leo_algo;

int main (int argc, char *argv[])
{
	for (unsigned loop = 0; loop < 10; ++loop)
	{
		cerr << "LOOP # " << loop << std::endl;
		// put random numbers into list
		vector<unsigned>	arr1;
		list<unsigned>		arr2;
		for (unsigned i = 0; i < COUNT; ++i)
			arr1.push_back((int) ((RANGE * 1.0 * rand())/(RAND_MAX + 1.0)));
		for (unsigned i = 0; i < COUNT; ++i)
			arr2.push_back((int) ((RANGE * 1.0 * rand())/(RAND_MAX + 1.0)));

		// sort
		sort(arr1.begin(), arr1.end());
		arr2.sort();

		// output array
		cerr << "\tArr1:\t";
		BOOST_FOREACH(unsigned i, arr1) 
			cerr << i << ", ";
		cerr << std::endl;
		cerr << "\tArr2:\t";
		BOOST_FOREACH(unsigned i, arr2) 
			cerr << i << ", ";
		cerr << std::endl;

		unsigned arr1_hit = 0;
		unsigned arr2_hit = 0;
		for (unsigned range = 1; range < 20; ++range)
		{
			bool is_within_range = any_element_within_range(arr1, arr2, range, arr1_hit, arr2_hit);
			if (is_within_range)
			{
				cerr << "\tWithin range [" << range << "]: " << arr1_hit << ", " << arr2_hit << std::endl;;
				break;
			}
		}

	}
	return(0);
}

